<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      li {
        list-style: none;
      }
      .he_book {
        width: 350px;
        background-color: #f5f5f5;
      }
      .title {
        padding: 15px 0;
        width: 100%;
        text-align: center;
        font-size: 30px;
        color: #9e5956;
      }
      .content {
        margin: 0 15px;
        padding: 7px;
        background-color: #fff;
      }
      .add_book {
        display: flex;
        width: 100%;
        height: 40px;
      }
      .add_book input {
        flex: 1;
        box-sizing: border-box;
        padding-left: 10px;
        height: 100%;
        border: 2px solid #c16056;
        outline-style: none;
        border-top-left-radius: 7px;
        border-bottom-left-radius: 7px;
      }
      .add_book input::placeholder {
        color: #ccc;
        font-style: italic;
      }
      .add {
        width: 80px;
        height: 100%;
        color: #fff;
        background-color: #c16056;
        border: none;
        font-size: 12px;
        border-top-right-radius: 7px;
        border-bottom-right-radius: 7px;
      }
      .book_list {
        width: 100%;
        /* height: 100px; */
        /* overflow-y: scroll; */
      }
      .book_list li {
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        padding: 10px 5px;
        width: 100%;
        border-bottom: 1px solid #ccc;
        font-size: 15px;
      }
      .del {
        color: #c16056;
      }
      .footer {
        box-sizing: border-box;
        padding: 10px;
        display: flex;
        justify-content: space-between;
        font-size: 12px;
        color: #a2a1a1;
      }
    </style>
  </head>
  <body>
    <div id="box">
      <div class="he_book">
        <div class="title">小黑记事本</div>
        <div class="content">
          <div class="add_book">
            <input type="text" v-model.trim="renwu" placeholder="请输入任务" />
            <button class="add" @click="add">添加任务</button>
          </div>
          <ul class="book_list">
            <li v-for="(item, index) in bookList" :key="item.id">
              <span>{{ index+1 }}. {{ item.msg }}</span>
              <span class="del" @click="del(item.id)">x</span>
            </li>
          </ul>
          <div class="footer">
            <div>合计:{{ sum }}</div>
            <div class="clear" @click="bookList = []">清空任务</div>
          </div>
        </div>
      </div>
    </div>
    <script src="./vue.js"></script>
    <script>
      // 小黑记事本
      new Vue({
        el: "#box",
        data: {
          renwu: "",
          bookList: [
            { id: 0, msg: "跑步锻炼20分钟" },
            { id: 1, msg: "跑步锻炼10分钟" },
            { id: 2, msg: "跑步锻炼5分钟" },
            { id: 3, msg: "跑步锻炼30分钟" },
          ],
        },
        methods: {
          add() {
            this.bookList.push({
              id: +new Date(),
              msg: this.renwu,
            });
            this.renwu = "";
          },
          del(id) {
            this.bookList = this.bookList.filter((item) => {
              return item.id !== id;
            });
          },
        },
        computed: {
          sum() {
            return this.bookList.length;
          },
        },
      });
    </script>
  </body>
</html>
